package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.StatsStoreService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.StatsStoreDto;
import com.huilian.iotbox.data.vo.StatsStoreVo;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @author 谢洛涛
 * @date 2021/5/8 16:49
 */
@RestController
@RequestMapping("/api/statsStore")
public class StatsStoreController extends UserInfoController {
    @Autowired
    private StatsStoreService statsStoreService;

    /**
     * 场地分析-小程序
     *
     * @param statsStoreDto
     * @param request
     * @return
     */
    @GetMapping("/findStatsStoreByApplet")
    public ServerResponse findStatsStoreByApplet(StatsStoreDto statsStoreDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return statsStoreService.findStatsStoreByApplet(statsStoreDto);
    }

    /**
     * 场地分析-公众号H5
     *
     * @param statsStoreDto
     * @param request
     * @return
     */
    @GetMapping("/findAllStoreStatisticsByUserIdAndDateTime")
    public ServerResponse findAllStoreStatisticsByUserIdAndDateTime(StatsStoreDto statsStoreDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return statsStoreService.findAllStoreStatisticsByUserIdAndDateTime(statsStoreDto);
    }

    /**
     * 经营统计-按场地-时间段-公众号H5
     *
     * @param request
     * @param statsStoreDto
     * @return
     */
    @PostMapping("/findStoreStatistics")
    public ServerResponse list(HttpServletRequest request, @RequestBody StatsStoreDto statsStoreDto) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(statsStoreService.findStoreStatistics(statsStoreDto));
    }


    /**
     * 经营统计-按场地-时间段-小程序
     *
     * @param request
     * @param statsStoreDto
     * @return
     */
    @PostMapping("/findStoreStatisticsByApplet")
    public ServerResponse findStoreStatisticsByApplet(HttpServletRequest request, @RequestBody StatsStoreDto statsStoreDto) throws ParseException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(statsStoreService.findStoreStats(statsStoreDto));
    }

    /**
     * 经营统计-按场地-时间段-小程序V2
     *
     * @param request
     * @param statsStoreDto
     * @return
     */
    @PostMapping("/findStoreStatisticsByAppletTwo")
    public ServerResponse findStoreStatisticsByAppletTwo(HttpServletRequest request, @RequestBody StatsStoreDto statsStoreDto) throws ParseException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(statsStoreService.findStoreStatsTwo(statsStoreDto));
    }


    /**
     * 根据开始结束时间, 场地ID, 查询日或月的统计数据
     */
    @PostMapping("/findStoreStatsStateList")
    public ServerResponse findStoreStatsStateList(HttpServletRequest request, @RequestBody StatsStoreDto statsStoreDto) throws ParseException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(statsStoreService.findStoreStatsStateList(statsStoreDto));
    }

    /**
     * 经营统计-全场地-时间段-小程序V3
     *
     * @param request
     * @param statsStoreDto
     * @return
     */
    @PostMapping("/findAllStatsStoreList")
    public ServerResponse findAllStatsStoreList(HttpServletRequest request, @RequestBody StatsStoreDto statsStoreDto) throws ParseException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(statsStoreService.findAllStatsStoreList(statsStoreDto));
    }


    @PostMapping("/findStatsStoreBranchHead")
    public ServerResponse findStatsStoreBranchHead(HttpServletRequest request, @RequestBody StatsStoreDto statsStoreDto) throws ExecutionException, InterruptedException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return statsStoreService.findStatsStoreBranchHead(statsStoreDto);
    }

    @PostMapping("/findStatsStoreBranchData")
    public ServerResponse findStatsStoreBranchData(HttpServletRequest request, @RequestBody StatsStoreDto statsStoreDto) throws ParseException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        statsStoreDto.setUserInfo(userInfo);
        return statsStoreService.findStatsStoreBranchData(statsStoreDto);
    }
}
